package com.ekgc.addressbook.service.impl;


import com.ekgc.addressbook.common.UserInfo;
import com.ekgc.addressbook.dao.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.Date;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public void register(UserInfo userInfo) {
        userInfo.setCreateTime(new Date());
        userInfo.setUpdateTime(new Date());
        userMapper.insertUser(userInfo);
    }

    @Override
    public boolean login(String PhoneNumber, String password) {
        UserInfo userInfo = userMapper.selectUserByPhoneNumber(PhoneNumber);
        return userInfo != null && userInfo.getUserPassword().equals(password);
    }

    @Override
    public String getUserID(String phoneNumber) {
        UserInfo userInfo = userMapper.selectUserByPhoneNumber(phoneNumber);
        return String.valueOf(userInfo != null ? userInfo.getId() : null);
    }
}